from PIL import Image
import struct
import imgs

# 假设数据是RGB565
width = 104
height = 160


def tojpg(fn, data):
    with open('bitmap.bin', 'wb') as f:
        # 写入你提供的十六进制数据
        hex_data = data
        for val in hex_data:
            f.write(struct.pack('<H', val & 0xFFFF))  # 小端RGB565

    # 读取并转换为RGB
    with open('bitmap.bin', 'rb') as f:
        data = f.read()

    img = Image.frombytes('RGB', (width, height), data, 'raw', 'RGB;16', 0, 1)
    img.save(f'{fn}.jpg')


tojpg('da0', imgs.da0);
tojpg('da1', imgs.da1);
tojpg('da2', imgs.da2);
tojpg('da3', imgs.da3);
tojpg('da4', imgs.da4);
tojpg('da5', imgs.da5);
tojpg('da6', imgs.da6);
tojpg('da7', imgs.da7);
tojpg('da8', imgs.da8);
tojpg('da9', imgs.da9);


    